package com.wxxymaker.edu.controller.view;

import com.blade.ioc.annotation.Inject;
import com.blade.mvc.RouteContext;
import com.blade.mvc.annotation.GetRoute;
import com.blade.mvc.annotation.JSON;
import com.blade.mvc.annotation.Param;
import com.blade.mvc.annotation.Path;
import com.blade.mvc.http.Request;
import com.blade.mvc.ui.RestResponse;
import com.wxxymaker.edu.service.SysRecordService;
import com.wxxymaker.edu.utils.BaseKit;

/**
 * @AUTHOR soft
 * @DATE 2018/9/6 16:47
 * @DESCRIBE 所有不需要做认证的视图
 */
@Path
public class PublicViewHandler {

    @Inject
    private SysRecordService recordService;

    @GetRoute("/403")
    @JSON
    public RestResponse _403(@Param(defaultValue = "资源不存在！") String msg) {
        return RestResponse.fail(403, msg);
    }

    /**
     * 主页
     */
    @GetRoute({"/", "/index"})
    public String index(Request request) {
        long all = recordService.countAll();
        long dayView = recordService.toDayView();

        request.attribute("allView", all);
        request.attribute("tdView", dayView);
        return "index";
    }

    /**
     * 所有课程页面
     */
    @GetRoute("/allClass")
    public String video(@Param(name = "spId", defaultValue = "0") Integer specialtyId,
                        @Param(name = "sbId", defaultValue = "0") Integer subjectId,
                        Request request) {
        request.attribute("spId", specialtyId);
        request.attribute("sbId", subjectId);
        return "allClass";
    }

    /**
     * 搜索页面
     * @param q 关键字
     */
    @GetRoute("/search")
    public String search(RouteContext ctx,
                         @Param String q) {
        ctx.attribute("q", q);
        return "search";
    }

    /**
     * 用户登录
     */
    @GetRoute("/login")
    public String login(Request request,
                        @Param String redirect) {
        String uri = BaseKit.from(redirect);
        request.attribute("redirect", uri);
        return "login";
    }

    /**
     * 用户注册页面
     */
    @GetRoute("/register")
    public String register() {
        return "register";
    }

    /**
     * 找回密码页面
     */
    @GetRoute("/getBack")
    public String passReset() {
        return "getBack";
    }

    /**
     * 没有访问权限页面
     */
    @GetRoute("/nopower")
    public String nopower() {
        return "nopower";
    }
}
